require "state_machine"

class PaperTypeRepo < Sequel::Model(:paper_type)
  plugin :validation_helpers
  
  state_machine :state, :initial => :enable do
    event :toggle do
      transition [:enable] => :disable, if: lambda {|e| e.enable?}
      transition [:disable] => :enable, if: lambda {|e| e.disable?}      
    end
  end
  
  def validate
    super
    validates_unique :name
    validates_presence [:name, :cycle]
  end

  def perfect
    values
  end
end
